/**
 * 
 */
package com.meiwenhui.sishuwujing.view;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.TextView;

import com.meiwenhui.sishuwujing.R;

/**
 * @file LoadingProgressDialog.java
 * @author linbin
 * @email linbin.java@gmail.com
 * @date 2013-1-8
 * @description
 */
public class LoadingProgressDialog extends Dialog {

	private Context context = null;
	private static LoadingProgressDialog loadingProgressDialog = null;

	public LoadingProgressDialog(Context context) {
		super(context);
		this.context = context;
	}

	public LoadingProgressDialog(Context context, int theme) {
		super(context, theme);
	}

	public static LoadingProgressDialog createDialog(Context context) {
		loadingProgressDialog = new LoadingProgressDialog(context, R.style.CustomProgressDialog);
		loadingProgressDialog.setContentView(R.layout.loading_progressdialog);
		loadingProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;

		return loadingProgressDialog;
	}

	public void onWindowFocusChanged(boolean hasFocus) {

		if (loadingProgressDialog == null) {
			return;
		}

		ImageView imageView = (ImageView) loadingProgressDialog.findViewById(R.id.loadingImageView);
		AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
		animationDrawable.start();
	}

	/**
	 * 
	 * [Summary] setTitile 标题
	 * 
	 * @param strTitle
	 * @return
	 * 
	 */
	public LoadingProgressDialog setTitile(String strTitle) {
		return loadingProgressDialog;
	}

	/**
	 * 
	 * [Summary] setMessage 提示内容
	 * 
	 * @param strMessage
	 * @return
	 * 
	 */
	public LoadingProgressDialog setMessage(String strMessage) {
		TextView tvMsg = (TextView) loadingProgressDialog.findViewById(R.id.id_tv_loadingmsg);

		if (tvMsg != null) {
			tvMsg.setText(strMessage);
		}

		return loadingProgressDialog;
	}

}
